package com.cakemallproject.Util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    private static final String jwtPwd = "callMall";
    public static String getToken(Map<String,Object> map) {
        return Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, jwtPwd)  //签名
                .setClaims(map)      //自定义载荷
                .setExpiration(new Date(System.currentTimeMillis() + 1000*60*60*5))      //过期时间 5小时
                .compact();
    }

    public static Claims parseToken(String token) {
        return Jwts.parser()
                .setSigningKey(jwtPwd)
                .parseClaimsJws(token)
                .getBody();
    }
}
